import $ from 'jquery'

const data = {
    /**
     * 设置用户权限
     * 通过递归的方式，找到需要跳转的路由名称，设置meta.roleAuth属性
     * @param data
     * @param name
     */
    setRoleAuth (data, name) {
        for (let i in data) {
            if (data[i].name == name) {
                data[i].meta.roleAuth = true
                break
            } else {
                this.setRoleAuth(data[i].children, name)
            }
        }
    },

    // 关闭 layui 弹窗
    closeLayuiTips () {
        $(function () {
            $('.content-wrapper').scroll(function () {
                $('.layui-table-tips').css('display', 'none')
            })

            let body = document.querySelector('body')
            body.addEventListener('click', function (e) {
                let elem = e.target || e.srcElement
                while (elem) {
                    let elemClassName = elem.className
                    if (elemClassName && (elemClassName.indexOf('layui-table-tips-main') !== -1)) {
                        return false
                    }
                    elem = elem.parentNode
                }
                $('.layui-table-tips').css('display', 'none')
            })
        })
    }
}

export default data
